package array.easy;

/**
 * 345.反转字符串中的元音字母
 */
public class reverseVowels {

    public static void main(String[] args) {
        System.out.println(myCode("leotcede"));
    }

    /**
     * 对撞指针
     * @return
     */
    public static String myCode(String s) {
        int p1 = 0;
        int p2 = s.length() - 1;
        StringBuffer sb = new StringBuffer(s);

        while (p1 < p2) {

            while (p1 < p2 && !isVowel(sb.charAt(p1))) {
                p1++;
            }
            while (p1 < p2 && !isVowel(sb.charAt(p2))) {
                p2--;
            }

            if (p1 < p2) {
                char tamp = sb.charAt(p1);
                sb.setCharAt(p1, sb.charAt(p2));
                sb.setCharAt(p2, tamp);
                p1++;
                p2--;
            }
        }
        return sb.toString();
    }

    public static boolean isVowel(char c) {
        switch (c) {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
                return true;
        }
        return false;
    }
}
